#include<bits/stdc++.h>
using namespace std;
const int MAXN=200,MAXM=6010,INF=0x7fffffff;
int n,m,head[MAXN*2],cnt,idx[MAXN*2],nxt[MAXN];
bool vis[MAXN];
struct edge
{
	int u,v,next,val;
}e[MAXM*2+MAXN*4];
void addedge(int x,int y,int z)
{
	e[cnt]=(edge){x,y,head[x],z};
	head[x]=cnt++;
	return;
}
void bfs()
{
	memset(idx,0,sizeof(idx));
	queue<int>q;
	idx[0]=1;
	q.push(0);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int i=head[u];~i;i=e[i].next)
		{
			int v=e[i].v;
			if(idx[v]||!e[i].val)continue;
			idx[v]=idx[u]+1;
			q.push(v);
		}
	}
	return;
}
int dfs(int u,int _min)
{
	if(u==n*2+1)return _min;
	int ret=0,k;
	for(int i=head[u];~i;i=e[i].next)
	{
		int v=e[i].v;
		if(idx[v]!=idx[u]+1||!e[i].val)continue;
		k=dfs(v,min(_min-ret,e[i].val));
		e[i].val-=k;
		e[i^1].val+=k;
		ret+=k;
		if(ret==_min)break;
	}
	return ret;
}
int main()
{
	memset(head,-1,sizeof(head));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(x,y+n,INF);
		addedge(y+n,x,0);
	}
	for(int i=1;i<=n;++i)
	{
		addedge(0,i,1);
		addedge(i,0,0);
		addedge(i+n,n*2+1,1);
		addedge(n*2+1,i+n,0);
	}
	int ans=0;
	while(true)
	{
		bfs();
		if(!idx[n*2+1])break;
		ans+=dfs(0,INF);
	}
	for(int i=0;i<=m*2-1;++i)
		if(e[i^1].val)nxt[e[i].u]=e[i].v-n;
	for(int i=1;i<=n;++i)
	{
		if(!vis[i])
		{
			int j=i;
			vis[i]=true;
			printf("%d ",i);
			while(nxt[j])
			{
				printf("%d ",nxt[j]);
				j=nxt[j];
				vis[j]=true;
			}
			puts("");
		}
	}
	printf("%d\n",n-ans);
	return 0;
}
